package org.zb.admin.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.zb.shiro.model.User;
import org.zb.shiro.service.UserService;

@Controller
public class IndexController {

	@Autowired
	private UserService userService;
	
	@GetMapping("/")
	public String index(ModelMap model){
		Subject subject = SecurityUtils.getSubject();
		Long userId = (Long) subject.getPrincipal();
		User user = userService.findById(userId);
		model.addAttribute("user",user);
		return "index";
	}
	
	@GetMapping("/welcome")
	public String welcome()
	{
		return "welcome";
	}
}
